const state = {
	wxappid: 'wx95d8956a1cd87925',
	ttappid: '',

	provider: 'weixin',
	openid: '',
	unionid: '',
	session_key: '',

	token: "",
	user_id: 0,
	username: "",
	nickname: "",
	avatar: "",
	iccid: "",
	order_id: "",
}

const getters = {
	getLoginInfo(state) {
		return state;
	}
}

const mutations = {
	setLoginInfo(state, payload) {
		Object.keys(payload).forEach((key) => {
			if (payload[key]) {
				state[key] = payload[key];
			}
		});
		uni.setStorageSync('login', state);
	},
	clearLoginInfo(state) {
		console.log("clearLoginInfo");
		Object.keys(state).forEach((key) => {
			if (key !== 'wxappid') {
				const type_of = typeof(state[key]);
				switch (type_of) {
					case 'string':
						state[key] = '';
						break;
					case 'number':
						state[key] = 0;
						break;
					default:
						state[key] = undefined;
						break;
				}
			}
		});
		uni.setStorageSync('login', state);
	},
}

export default {
	namespaced: true, // 开启namespace:true，该模块就成为命名空间模块了
	state,
	getters,
	mutations,
}